package com.origin.baselibrary.activity.style

import android.util.Log
import android.view.LayoutInflater
import android.view.View
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.origin.baselibrary.R
import com.origin.baselibrary.activity.BaseActivity
import com.origin.baselibrary.databinding.LayoutActivityImmersiveBinding
import com.origin.utils.log.LogUtils
import com.origin.utils.statusBar.StatusBarUtil
import kotlinx.android.synthetic.main.layout_activity_immersive.*

//已经适配通知栏
abstract class ImmersiveActivity<VB : ViewDataBinding>(var contentViewLayout: Int = 0, open var isSafeDis: Boolean = true, open var isOpenImmersive: Boolean = true) : BaseActivity<LayoutActivityImmersiveBinding>(R.layout.layout_activity_immersive) {

    val contentViewBinding: VB by lazy {
        DataBindingUtil.inflate<VB>(
            LayoutInflater.from(mContext),
            contentViewLayout, null, false
        )
    }


//    abstract fun contentView(): Int

    abstract fun initContentView()

//    final override fun getContentViewId(): Int = R.layout.layout_activity_immersive


    final override fun initUI() {
        if (isOpenImmersive) {
            StatusBarUtil.setTranslucentForImageView(this@ImmersiveActivity, 0, transparentBg)
        }
        flContentView.addView(contentViewBinding.root, 1)
        initContentView()

    }

    override fun onWindowFocusChanged(hasFocus: Boolean) {
        super.onWindowFocusChanged(hasFocus)
        if (hasFocus && isSafeDis) {
            val safeHeight = StatusBarUtil.getStatusBarHeight(this);
            Log.e("获取高度", "safeHeight  " + safeHeight)
            contentViewBinding.root.setPadding(0, safeHeight, 0, 0)
        }
    }
}